// Copyright (C) 2006 Taylor L. Riché <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#ifndef ETH_PACKET_HH
#define ETH_PACKET_HH

#include <linux/if_ether.h>

#include "Packet.hh"

namespace pktTypes {

  const unsigned int ETH_HSIZE = 0xe; // 14

  struct ethAddr
  {
    unsigned char data[ETH_ALEN];
  }__attribute__((packed));

  class Eth_Packet : public Packet
  {
  protected:
    ethhdr * ethHdr;
    payload_t eth_payload;
  public:
    Eth_Packet() : ethHdr(NULL), eth_payload(NULL) {}
    Eth_Packet(const Packet & pkt) : Packet(pkt)
    {
      assert(payload != NULL);
      ethHdr = (ethhdr *)payload;
      eth_payload = ((payload_t)ethHdr) + ETH_HSIZE;
    }
    void setSrcAddress(ethAddr sa) {
      for(int i = 0; i < ETH_ALEN; ++i) {
	ethHdr->h_source[i] = sa.data[i];
      }
    }
    void setDstAddress(ethAddr sa) {
      for(int i = 0; i < ETH_ALEN; ++i) {
	ethHdr->h_dest[i] = sa.data[i];
      }
    }
    void setEthProt(uint16_t p) {ethHdr->h_proto = htons(p);}
  };

}

#endif // ETH_PACKET_HH
